/**
 * 一,用正则表达式来将字符串"I?���love�??�the�?great�?�?wall�in��?beijing"
 * 更改为:"I love the Great Wall in Beijing",主要是为了解决编码的问题导致的问题,规律:

 1,乱码只有两种特殊字符分别是'?'和'�';

 2,如果乱码的末尾是'?'则它的下一位字母肯定是大写;

 二,不使用类似for,while循环控制语句和js本身自带方法(如:forEach)的情况下,
 实现将一个空数组[]赋值成[0,******************],范围0-100便可。

 三,设计一个自由可灵活配置的时间调度器,有a,b,c,d...很多个需要被调度的方法(方法名称的命名可随意),
 调度有两种形式,一个是顺序调用(例如调度完a后才能调度b),一个是间隔某个时间进行循环调度。用一个统一的方法进行封装可以实现下列的例子:

 1,可以为5秒后调用a,3秒后调用b,10秒后调用。c...z方法不执行(不执行的方法可以设计成不传递参数),
 那么在第14秒的时候开始重新从0秒循环,又变成第一秒后调用a,3秒后调用b,这样循环往复;

 2,每间隔6秒调用一次a,每间隔4秒调用一次b,c...z方法不执行;

 3,第一秒先执行a,3秒后执行b,但是c却是每间隔3秒执行一次,d是每间隔4秒执行一次,a和b是每4秒进行一次循环;

 4,a不执行,b和c每间隔3秒执行一次,d不执行;
 */
let str = "I?���love�??�the�?great�?�?wall�in��?beijing";
let myArray;
while ((myArray = /�\?[a-z]/g.exec(str)) !== null) {
    str = str.substring(0, myArray.index + 2) +
        str[myArray.index + 2].toUpperCase() +
        str.substring(myArray.index + 2 + 1, str.length);
}
console.log(str.replace(/[�?]/g, ' ').replace(/\s+/g, ' '))


let arr = [];
let num = 0;
function addNum() {
    if (num<=100) {
        arr.push(num);
        num ++;
        addNum();
    }
}
addNum();
console.log(arr)

class TimeScheduler {
    constructor() {
        this.events = [];
        this.orderCallStack = [];
        this.ownCallStack = [];
    }
    add(fn = () => {}, orderExec = false, timeout = 3) {
        let fnc;
        if (orderExec) {
            fnc = () => {
                setTimeout(() => {
                    fn();
                    this.next();
                }, timeout * 1000)
            };
        } else {
            fnc = () => {
                setInterval(() => {
                    fn()
                }, timeout * 1000)
            };
        }
        this.events.push({
            fnc,
            orderExec
        })
    }
    remove(fnc = () => {}) {
        this.events = this.events.filter(item => item.fnc === fnc);
    }
    start() {
        this.orderCallStack = this.events.filter(item => !!item.orderExec);
        this.ownCallStack = this.events.filter(item => !item.orderExec);
        this.ownCallStack.forEach(item => item.fnc());
        this.next();
    }
    next() {
        let obj = this.orderCallStack.shift() || {};
        if (obj.fnc) {
            this.orderCallStack.push(obj);
            obj.fnc();
        }
    }
}

let a = () => {
    console.log("a");
}
let b = () => {
    console.log("b");
}
let c = () => {
    console.log("c");
}
let d = () => {
    console.log("d");
}
const timeScheduler1 = new TimeScheduler();
timeScheduler1.add(a, true, 5);
timeScheduler1.add(b, true, 3);
timeScheduler1.add(c, true, 10);
timeScheduler1.start();
const timeScheduler2 = new TimeScheduler();
timeScheduler2.add(a, false, 6);
timeScheduler2.add(b, false, 4);
timeScheduler2.start();
const timeScheduler3 = new TimeScheduler();
timeScheduler3.add(a, true, 1);
timeScheduler3.start();
timeScheduler3.remove(a)
timeScheduler3.add(a, true, 4);
timeScheduler3.add(b, true, 3);
timeScheduler3.add(c, true, 3);
timeScheduler3.add(d, true, 4);
timeScheduler3.start();
const timeScheduler4 = new TimeScheduler();
timeScheduler4.add(b, true, 3);
timeScheduler4.add(c, true, 3);
timeScheduler4.start();